<template>
  <div class="user-info">
    <el-dropdown>
      <span class="el-dropdown-link">
        <img class="avatar" src="~@/assets/img/avatar.png" alt="avatar" />
        <span>{{ name }}</span>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="handleExitClick">退出登录</el-dropdown-item>
          <el-dropdown-item>用户信息</el-dropdown-item>
          <el-dropdown-item>系统管理</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
<script lang="ts">
import { useStore } from 'vuex'
import { computed, defineComponent } from 'vue'
import LocalCache from '@/utils/cache'
import { useRouter } from 'vue-router'
export default defineComponent({
  setup() {
    const store = useStore()
    const name = computed(() => store.state.login.userInfo.name)
    // 退出登录 删除token
    const router = useRouter()
    const handleExitClick = () => {
      LocalCache.deleteCache('token')
      router.push('/main')
    }
    return {
      name,
      handleExitClick
    }
  }
})
</script>
<style lang="less" scoped>
.user-info {
  margin-top: 5px;
  .el-dropdown-link {
    display: flex;
    align-items: center;
    .avatar {
      width: 30px;
      height: 30px;
      margin-right: 10px;
    }
  }
}
</style>
